import {createRouter, createWebHashHistory} from 'vue-router'
import maineRouter from './maineRouter'
import {getToken} from '@/utils/user.js'

const routes = [
    {
        path: '/',
        name: 'index',
        component: () => import('../layout/index.vue'),
        meta: {
            keepAlive: false
        },
        children: [
            {
                path: '/',
                name: 'home',
                component: () => import('@/views/home/Home.vue'),
                meta: {
                    keepAlive: true
                }
            },


            {
                path: '/shoppingCart',
                name: 'shoppingCart',
                component: () => import('../views/shoppingCart/ShoppingCart.vue'),
                meta: {
                    keepAlive: false
                }
            },
            {
                path: '/mine',
                name: 'mine',
                component: () => import('../views/mine/Mine.vue'),
                meta: {
                    keepAlive: false
                }
            }
        ]
    },
    {
        path: '/activityReservation/list',
        name: 'activityReservation',
        component: () => import('../views/activityReservation-list/ScenicList.vue'),
        meta: {
            keepAlive: false
        }
    },
    {
        path: '/coupon',
        name: 'couponList',
        component: () => import('../views/coupon/Coupon.vue'),
        meta: {
            keepAlive: true
        }
    },
    {
        path: '/coupon-detail',
        name: 'couponDetail',
        component: () => import('../views/coupon/coupon-detail.vue'),
        meta: {
            keepAlive: false
        }
    },
    {
        path: '/coupon-order-detail/:id',
        name: 'couponOrderDetail',
        component: () => import('../views/activityPages/order/coupon-order-detail.vue'),
        meta: {
            keepAlive: false
        }
    },
    {
        path: '/order',
        name: 'order',
        component: () => import('../views/order/Order.vue')
    },
    {
        path: '/mall-order',
        name: 'mallOrder',
        component: () => import('../views/order/MallOrder.vue')
    },
    {
        path: '/activity-order',
        name: 'ActivityOrder',
        component: () => import('../views/order/ActivityOrder.vue'),
        meta: {
            keepAlive: true
        },
    },
    {
        path: '/share-order',
        name: 'shareOrder',
        component: () => import('../views/order/ShareOrder.vue')
    },
    {
        path: '/convenience-order',
        name: 'convenienceOrder',
        component: () => import('../views/order/ConvenienceOrder.vue')
    },
    {
        path: '/hs/:id',
        name: 'haishuaOrderDetail',
        component: () => import('../views/order-detail/HaishuaOrderDetail.vue')
    },
    {
        path: '/order/:id',
        name: 'scenicOrderDetail',
        component: () => import('../views/order-detail/OrderDetail.vue')
    },
    {
        path: '/activity-order/:id',
        name: 'activityOrderDetail',
        component: () => import('../views/activityPages/order/order-detail.vue')
    },
    {
        path: '/share-order/:id',
        name: 'shareOrderDetail',
        component: () => import('../views/activityPages/office-share/common-share-order-detail.vue')
    },
    // {
    //   path: '/refund-request',
    //   name: 'refundRequest',
    //   component: () => import('../views/activityPages/refund/refund.vue')
    // },
    {
        path: '/refund-list',
        name: 'refundList',
        component: () => import('../views/activityPages/refund/refund-list.vue')
    },
    {
        path: '/refund-detail',
        name: 'refundDetail',
        component: () => import('../views/activityPages/refund/refund-detail.vue')
    },
    {
        path: '/pandaOrder/:id',
        name: 'pandaOrderDetail',
        component: () => import('../views/order-detail/PandaOrderDetail.vue'),
    },
    {
        path: '/scenic/refund/:id',
        name: 'scenicOrderRefund',
        component: () => import('@/views/order-refund/OrderRefund.vue')
    },
    {
        path: '/scenicspot/:id',
        name: 'scenicDetail',
        component: () => import('../views/scenicspot/ScenicspotDetails.vue')
    },
    {
        path: '/activityAreaDetails/:id/:name',
        name: 'activityAreaDetails',
        component: () => import('../views/activityAreaDetails/ScenicspotDetails.vue')
    },
    {
        path: '/pandascenicspot/:id',
        name: 'pandaScenicDetail',
        component: () => import('../views/scenicspot/PandaScenicDetails.vue')
    },
    {
        path: '/scenicordel',
        name: 'scenicOrder',
        component: () => import('../views/orderconfirmation/scenicordel.vue'),
        meta: {
            keepAlive: false
        }
    },
    {
        path: '/verifyScenicordel',
        name: 'verifyScenicordel',
        component: () => import('../views/orderconfirmation/verifyScenicordel.vue'),
        meta: {
            keepAlive: false
        }
    },
    {
        path: '/activityVerifyScenicordel',
        name: 'activityVerifyScenicordel',
        component: () => import('../views/orderconfirmation/activityVerifyScenicordel.vue'),
        meta: {
            keepAlive: false
        }
    },
    {
        path: '/pandaScenicOrder',
        name: 'pandaScenicOrder',
        component: () => import('../views/orderconfirmation/PandaScenicOrder.vue'),
        meta: {
            keepAlive: false
        }
    },
    {
        path: '/Hotelorder',
        name: 'hotelorder',
        component: () => import('../views/orderconfirmation/Hotelorder.vue'),
        meta: {
            keepAlive: false
        }
    },
    {
        path: '/scenicspot',
        name: 'scenicspot',
        component: () => import('../views/scenicspot/ScenicspotDetails.vue'),
        meta: {
            keepAlive: false
        }
    },
    {
        path: '/search',
        name: 'search',
        component: () => import('../views/search/Search.vue')
    },
    {
        path: '/search/:searchKey',
        name: 'searchResult',
        component: () => import('../views/search-result/SearchResult.vue')
    },
    {
        path: '/scenic/quality/list',
        name: 'quality_scenic',
        component: () => import('../views/quality-scenic/QualityScenic.vue')
    },
    {
        path: '/result/list',
        name: 'resultList',
        component: () => import('../views/scenic-list/ScenicList.vue'),
        meta: {
            keepAlive: true
        }
    },

    {
        path: '/login',
        name: 'login',
        component: () => import('../views/login/Login.vue'),
        // beforeEnter (to, from, next) {
        //   if (from.name !== 'login') {
        //     // next({
        //     //   name: 'login',
        //     //   query: {
        //     //     from: from.path
        //     //   }
        //     // })
        //     next('/login')
        //   } else {
        //     next()
        //   }
        //   console.log('to', to)
        //   console.log('from', from)
        // }
    },
    {
        path: '/detail',
        name: 'detail',
        component: () => import('../views/detail/Detail.vue')
    },
    {
        path: '/demo',
        name: 'demo',
        component: () => import('../views/demo.vue'),
    },
    {
        path: '/pedestrianmanagement',
        name: 'pedestrianmanagement',
        component: () => import('../views/pedestrianmanagement/Pedestrianmanagement.vue')
    },
    {
        path: '/addapedestrian',
        name: 'addApedestrian',
        component: () => import('../views/addapedestrian/addapedestrian.vue')
    },
    {
        path: '/pedestrianedit',
        name: 'pedestrianedit',
        component: () => import('../views/pedestrianedit/pedestrianedit.vue')
    },
    // {
    //   path: '/coupondetail',
    //   name: 'coupondetail',
    //   component: () => import('../views/coupondetail/coupondetail.vue')
    // },
    {
        path: '/qualitymerchant',
        name: 'qualitymerchant',
        component: () => import('../views/qualitymerchant/qualitymerchant.vue')
    },
    {
        path: '/scenic/merchants/:id',
        name: 'ScenicMerchants',
        component: () => import('../views/scenic-merchants/ScenicMerchants.vue')
    },
    {
        path: '/scenic/merchants/commodity',
        name: 'ScenicMerchantsCommodity',
        component: () => import('../views/scenic-merchants-commodity/ScenicMerchantsCommodity.vue')
    },
    {
        path: '/settinginterface',
        name: 'settinginterface',
        component: () => import('../views/settinginterface/settinginterface.vue')
    },
    {
        path: '/settinginterface/components/changepassword',
        name: 'changepassword',
        component: () => import('../views/settinginterface/components/changepassword.vue')
    },
    {
        path: '/hotpot/:id',
        name: 'hotpotDetail',
        component: () => import('../views/hotpot-detail/HotPotDetail.vue')
    },
    {
        path: '/groggery',
        name: 'groggery',
        component: () => import('../views/groggery/groggerydetail.vue')
    },
    {
        path: '/hotel-detail/:id',
        name: 'hotelDetail',
        component: () => import('../views/hotel-detail/HotelDetail.vue')
    },
    {
        path: '/goldenCard/signedscenicspots',
        name: 'signedscenicspots',
        component: () => import('../views/goldenCard/signedscenicspots.vue')
    },
    {
        path: '/goldenCard/spot/:id',
        name: 'signedscenicspot',
        component: () => import('../views/goldenCard/spot.vue')
    },
    {
        path: '/goldenCard/activation',
        name: 'goldenCardActivation',
        component: () => import('../views/goldenCard/activation.vue')
    },
    {
        path: '/input-code',
        name: 'hotelDetail',
        component: () => import('../views/input-code/InputCode.vue')
    },
    {
        path: '/panda-details',
        name: 'pandaDetails',
        component: () => import('../views/panda-details/PandaDetails.vue')
    },
    {
        path: '/my-card',
        name: 'myCard',
        component: () => import('../views/my-card/MyCard.vue')
    },
    {
        path: '/haishua-details',
        name: 'haishuaDetails',
        component: () => import('../views/haishua-details/HaishuaDetails.vue')
    },
    {
        path: '/my-address',
        name: '/myAddress',
        component: () => import('../views/address/my-address.vue'),

    },
    {
        path: '/my-address/edit',
        name: '/myAddressEdit',
        component: () => import('../views/address/address-edit.vue'),
    },
    {
        path: '/scan',
        name: 'scan',
        component: () => import('../views/scanqr/ScanQr.vue'),
    },


    ...maineRouter,
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

// GOOD
router.beforeEach((to, from, next) => {
    // const token = getToken()
    // if ((to.name !== 'login' && !token)) {
    //   next({ name: 'login' })
    // } else {
    //   next()
    // }

    console.log(from.fullPath, 'from.fullPath')
    localStorage.setItem('prevFullPath', from.fullPath)

    next()
})


export default router
